<?php
try {
	if(Authenticate::adminLogin($_POST['email'], $_POST['password'])){
		if(Authenticate::getAdminType()==Authenticate::TYPE_ACCOUNTING){
			echo json_encode(array('success'=> true, 'redir'=> 'old.php?page=accounting/payment'));
		}
		else if(Authenticate::getAdminType()==Authenticate::TYPE_TECHNIC){
			echo json_encode(array('success'=> true, 'redir'=> 'old.php?page=technic/qa'));
		}
		exit();
	}
	
	Authenticate::login($_POST['email'], $_POST['password']);
	if(Authenticate::getErrorNo() === 0){
		echo json_encode(array('success'=> true));
		exit();
	}
	else if(Authenticate::getErrorNo() === Authenticate::EMAIL_NOT_FOUND){
		throw new Exception('ไม่พบ email นี้', 1001);
	}
	else if(Authenticate::getErrorNo() === Authenticate::PASSWORD_INVALID){
		throw new Exception('password ผิด', 1002);
	}
	else if(Authenticate::getErrorNo() === Authenticate::ACCOUNT_NOT_VALIDATE){
		throw new Exception('Account นี้ ยังไม่ได้ทำการ Activate', 1003);
	}
}
catch (Exception $ex){
	echo json_encode(array('success'=>false, 'message'=> $ex->getMessage(), 'code'=> $ex->getCode()));
    //throw $ex;
}